<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Laravel\Passport\Passport;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        // $this->registerPolicies();

        // passport 的路由（授权码、令牌等）
        Passport::routes();

        // 启用 隐式授权令牌
        Passport::enableImplicitGrant();

        Passport::loadKeysFrom(storage_path());
        // Passport::loadKeysFrom('/storage');
        // 加载的是
        // file:///storage\oauth-private.key
        // 显然不对。

        Passport::tokensExpireIn(now()->addDays(15));
        Passport::refreshTokensExpireIn(now()->addDays(30));
        Passport::personalAccessTokensExpireIn(now()->addMonths(6));
        // 启用个人访问令牌（用户向自己发放令牌）
        Passport::personalAccessClientId('1');
    }
}
